package ar.uade.edu.fain.ad.server.service;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import ar.uade.edu.fain.ad.common.exception.AccesoDenegadoException;
import ar.uade.edu.fain.ad.common.remote.EmpleadoServicioRemoto;
import ar.uade.edu.fain.ad.common.transfer.LoginVO;
import ar.uade.edu.fain.ad.server.business.Empleado;
import ar.uade.edu.fain.ad.server.dao.EmpleadoDAO;

public class EmpleadoSRV extends UnicastRemoteObject implements
		EmpleadoServicioRemoto {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private EmpleadoDAO empleadoDAO;

	public EmpleadoSRV() throws RemoteException {
		super();
	}

	public EmpleadoDAO getEmpleadoDAO() {
		return empleadoDAO;
	}

	public void setEmpleadoDAO(EmpleadoDAO empleadoDAO) {
		this.empleadoDAO = empleadoDAO;
	}

	@Override
	public LoginVO login(String username, String password)
			throws RemoteException, AccesoDenegadoException {
		final Empleado empleado = getEmpleadoDAO().buscar(username, password);
		if (empleado == null) {
			throw new AccesoDenegadoException(username);
		} else {
			return empleado.createLoginVO();
		}
	}

}
